package com.fastfood.model.blo;

import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.List;

import com.fastfood.model.dao.OrderDAO;
import com.fastfood.model.dao.Report;
import com.fastfood.model.dto.Order;
import com.fastfood.util.DBConnectionPool;

public class OrderBLO {

	private OrderDAO dao = new OrderDAO();
	
	public boolean addOrder(Order order) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.addOrder(conn, order);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public List<Report> getReportsByYear(int year) {
		List<Report> reports = null;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			reports = dao.getReportsByYear(conn, year);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return reports;
	}
	
	public List<Report> getReportsByDate(Date startDate, Date endDate) {
		List<Report> reports = null;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			reports = dao.getReportsByDate(conn, startDate, endDate);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return reports;
	}
}
